<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>场馆管理 </title>
		<%@ include file="/WEB-INF/jspf/taglibs.jspf"%>
		<%@ include file="/WEB-INF/jspf/statics.jspf"%>
</head>
<body>
<div id="wrapper">

    <div class="submit-form pusht">
        <form name="submit-form" id="submit-form" enctype="multipart/form-data">
            <table class="form label-colored-form">
                <c:if test="${operationType=='add'}">
                    <tbody>
                    <tr class="sprite">
                        <td class="label-td"><label>场馆名称：</label></td>
                        <td><input type="text" name="venueName" id="venueName" value="" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>场馆别名：</label></td>
                        <td><input type="text" name="venueAlias" id="venueAlias" value="" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>场馆描述：</label></td>
                        <td><textarea name="venueDescription" style="width:332px;height:100px;resize:none; "></textarea></td>
                    </tr>
                   <tr class="sprite">
                        <td class="label-td"><label>状态：</label></td>
                        <td>
                            <select name="status" id="status">
                                <option value=1>启用</option>
                                <option value=2>禁用</option>
                            </select>
                        </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label></label></td>
                        <td>
                            <button class="btn btn-primary" id="btn_confirm">添加</button>
                        </td>
                    </tr>
                    </tbody>
                </c:if>
                
                
                <c:if test="${operationType !='add'}">
                    <input type="hidden" name="id" value="${venue.id}"/>
                    <tbody>
                    <tr class="sprite">
                        <td class="label-td"><label>场馆名称：</label></td>
                        <td><input type="text" name="venueName" id="venueName" value="${venue.venueName }" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>场馆别名：</label></td>
                        <td><input type="text" name="venueAlias" id="venueAlias" value="${venue.venueAlias }" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>场馆描述：</label></td>
                        <td><textarea name="venueDescription" style="width:332px;height:100px;resize:none; ">${venue.venueDescription }</textarea></td>
                    </tr>
                   <tr class="sprite">
                        <td class="label-td"><label>状态：</label></td>
                        <td>
                            <select name="status" id="status">
                                <option value=1 <c:if test="${venue.status==1 }">selected</c:if>>启用</option>
                                <option value=2 <c:if test="${venue.status==2 }">selected</c:if>>禁用</option>
                            </select>
                        </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label></label></td>
                        <td>
                            <button class="btn btn-primary" id="btn_confirm1">保存</button>
                        </td>
                    </tr>
                    </tbody>
                </c:if>
            </table>
        </form>
    </div>
</div>
</body>
</html>
<script type="text/javascript" src="${ctx }/js/jquery.form.js"></script>
<script type="text/javascript">
  $(document).ready(function () {
      // 给确认按钮绑定点击事件
      $("#btn_confirm").click(function (e) {
          e.preventDefault();
          if(subimtBtn('add')){
          	dialog_close();
          }
      });

      $("#btn_confirm1").click(function (e) {
          e.preventDefault();
          if(subimtBtn('update')){
          	dialog_close();
          }
          
      });
      $("#venueName").focus(function(){
    	  $("#venueName").next().text('');
      });
      $("#venueAlias").focus(function(){
    	  $("#venueAlias").next().text('');
      });
  });
  
  function checkForm(){
	  values = $("#submit-form").serializeArray();  
	  
	  var values, index;  
	  var result=true;
	  
	     for (index = 0; index < values.length; ++index)  
	    {  
	      if (values[index].name == "venueName")  
	      {  
	    	  if(values[index].value=="" || values[index].value==null){
	    		  result=false;
	    		  $("#venueName").next().text("场馆名称不能为空!");
	    		  break;
	    	  }    	  
	      }  
	      if (values[index].name == "venueAlias")  
	      {  
	    	  if(values[index].value=="" || values[index].value==null){
	    		  result=false;
	    		  $("#venueAlias").next().text("场馆别名不能为空!");
	    		  break;
	    	  }  
	      }
	    }  
	     return result;
  }
  
  function subimtBtn(type) {  
	  if(!checkForm()){
		  return false;
	  }
      var form = $("#submit-form");  
      var options  = {    
          url:'${ctx }/equipment/update_venue/'+type,    
          type:'post',    
          success:function(json)    
          {    
          	if (json == "success") {
              	parent.document.getElementById('success').click();
              } else {
              	parent.document.getElementById('fail').click();
              }
          }    
      };    
      form.ajaxSubmit(options);  
      dialog_close({callBack: function () {
          parent.document.getElementById('btn-primary').click();
      }});
  }  
</script>